<template>
  <el-select style="width: 100%" v-model="supplierName" clearable filterable placeholder="供货方"
             @change="selectCompany" value-key="id">
    <el-option
      v-for="item in companyList"
      :key="item.id"
      :label="item.name"
      :value="item">
    </el-option>
  </el-select>
</template>

<script>
import {list} from '@/api/customer'
import utils from '../../utils/utils.js'
import {companyList} from "@/api/report";
export default{
  // props:["supplierName"],
  props:{
    queryTitle:{
      type:String,
      value:'供应商'
    },
    supplierName:{
      type:String,
      // default:'',
      require:true
    },
    supplierId:{
      type:[String,Number],
      // default:'2',
      require:true
    }
  },
  data(){
    return{
      query:{
        id:'',
        name:"",
      },
      companyList:[],
      name:'',
      type:1,
      supplierName:"",

    }
  },

  watch:{
    supplierName(newval,oldval){
      this.supplierName=newval
    },
  },
  created() {
    // this.supplierName=this.name
    // console.log(this.supplierId,'su-id',this.supplierName)
    this.loadCompany()
  },
  methods:{
    selectCompany(data) {
      if(!utils.isNull(data)){
        this.query.id = data.id
        this.query.name = data.name
      }else{
        this.query.id = ''
        this.query.name = ''
      }
      this.$emit('querySupplier',this.query)
    },
    loadCompany() {
      var _this = this
      _this.companyList = []
      let params = new URLSearchParams();
      list(params).then(response => {
        console.log(response);
        response.data.data.forEach(item =>{
          if(item.type == this.type){
            _this.companyList.push(item)
          }
        })
      }).catch(error => {
        console.log('error!!')
      });
    },
  }
}
</script>

<style>
</style>

